package com.zz.ecommerce.togatherDeclareMgr.custDeclarationUpload.dao;

import com.zz.ecommerce.togatherDeclareMgr.common.bean.TCargo;
import com.zz.ecommerce.togatherDeclareMgr.common.bean.TContainers;
import com.zz.ecommerce.togatherDeclareMgr.common.bean.TDocuments;
import com.zz.ecommerce.togatherDeclareMgr.common.bean.TEntryInfo;
import com.zz.ecommerce.togatherDeclareMgr.custDeclarationUpload.bean.MsgDecHistory;
import com.zz.ecommerce.utils.SqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <一句话功能描述>
 * <功能详细描述>
 *
 * @author Administrator
 * @date 2015/8/15,16:34
 */
@Repository
public interface CargoCustDao {

    @SelectProvider(type = SqlProvider.class, method = "getSequence10")
    String getSequence10();

    /**
     * 查询海关表头
     *
     * @param tableName
     * @param entryInfo
     * @param order
     * @return
     */
    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    TEntryInfo queryEntryInfo(@Param("tableName") String tableName,
                              @Param("qryObj") TEntryInfo entryInfo,
                              @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectAll")
    List<TCargo> queryAllCargo(@Param("tableName") String tableName, @Param("qryObj") TCargo qryCargo,
                               @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    TContainers queryOneTDocuments(@Param("tableName") String tableName,
                                   @Param("qryObj") TDocuments documents,
                                   @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    List<TContainers> queryContainerList(@Param("tableName") String tableName,
                                         @Param("qryObj") TContainers containers,
                                         @Param("start") final int start,
                                         @Param("end") final int end,
                                         @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectCount")
    long getContainerCount(@Param("tableName") String tableName,
                           @Param("qryObj") TContainers containers);

    @SelectProvider(type = SqlProvider.class, method = "selectOne")
    TContainers queryContainerInfo(@Param("tableName") String tableName,
                                   @Param("qryObj") TContainers containers,
                                   @Param("sortOrder") String order);

    @Insert("INSERT INTO T_CONTAINERS\n" +
            "(INDX,CON_INDX,CONTAINTY,CONTAINNO,CONTAINWEIGHT)\n" +
            " VALUES \n" +
            "(#{indx},#{conIndx},#{containty},#{containno},#{containweight,jdbcType=NUMERIC})\n")
    boolean saveContainerInfo(TContainers containers);

    @Update("UPDATE T_CONTAINERS T SET \n" +
            "CONTAINTY = #{containty}," +
            "CONTAINNO = #{containno}," +
            "CONTAINWEIGHT = #{containweight}\n" +
            "WHERE INDX = #{indx} ")
    boolean updateContainerInfo(TContainers containers);

    @Delete("DELETE FROM T_CONTAINERS T " +
            "WHERE INDX = #{indx} \n")
    boolean deleteContainerInfo(TContainers containers);


    @InsertProvider(type = SqlProvider.class, method = "insert")
    boolean inserTDocuments(@Param("tableName") String tableName,
                            @Param("insertObj") TDocuments documents);

    @InsertProvider(type = SqlProvider.class, method = "update")
    boolean updateTDocuments(@Param("tableName") String tableName,
                             @Param("updateObj") TDocuments documents, @Param("updateCondition") String whereCondition);

    @SelectProvider(type = SqlProvider.class, method = "selectByPage")
    List<TDocuments> queryAccessoryFileList(@Param("tableName") String tableName,
                                            @Param("qryObj") TDocuments tDocuments,
                                            @Param("start") final int start,
                                            @Param("end") final int end,
                                            @Param("sortOrder") String order);

    @Select("SELECT * FROM (SELECT ROWNUM AS ROWNUM_, T.* FROM (" +
            "SELECT T.INDX,T.CON_INDX,T.DOCUMENTSCO,T.DOCUMENTSCO_NAME,T.DOCUMENTSNO,T.DOCUMENTSCN,\n" +
            "       T.FILE_ID,U.FILE_NAME \n" +
            "  FROM V_DOCUMENTS_ATTACH_LIST T,UPLOAD_FILE U\n" +
            " WHERE T.FILE_ID = U.FILE_ID(+)" +
            "   AND T.CON_INDX=#{qryObj.conIndx}"+
            " ORDER BY #{sortOrder}) T" +
            " WHERE ROWNUM <= #{end}) T" +
            " WHERE T.ROWNUM_ >= #{start}")
    List<TDocuments> queryAccessoryList(@Param("tableName") String tableName,
                                        @Param("qryObj") TDocuments tDocuments,
                                        @Param("start") final int start,
                                        @Param("end") final int end,
                                        @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectCount")
    long getAccessoryCount(@Param("tableName") String tableName,
                           @Param("qryObj") TDocuments tDocuments);

    @Delete("DELETE FROM T_DOCUMENTS WHERE INDX =#{indx}")
    boolean deleteTDocuments(String indx);

    @SelectProvider(type = SqlProvider.class, method = "selectAll")
    List<TContainers> queryAllContainer(@Param("tableName") String tableName, @Param("qryObj") TContainers qryContainer,
                                        @Param("sortOrder") String order);

    @SelectProvider(type = SqlProvider.class, method = "selectAll")
    List<TDocuments> queryAllDocument(@Param("tableName") String tableName, @Param("qryObj") TDocuments qryDocuments,
                                      @Param("sortOrder") String order);

    @Update("UPDATE T_ENTRYINFO SET STATUS = #{status} WHERE CON_INDX=#{conIndx}")
    int updateDeclareCustStatus(@Param("conIndx") String conIndx, @Param("status") String status);

    @InsertProvider(type = SqlProvider.class, method = "insert")
    boolean inserMsgDecHistory(@Param("tableName") String tableName,
                               @Param("insertObj") MsgDecHistory msgDecHistory);
}
